﻿using UnityEngine;
using System.IO;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace TinyAsset
{
    public class AssetBundleUtility
    {
#if UNITY_EDITOR

        const string kStrUseAssetDatabase = "UseAssetDatabase";

        public static bool kUseAssetDatabase
        {
            get { return EditorPrefs.GetBool(kStrUseAssetDatabase, true); }
            set { EditorPrefs.SetBool(kStrUseAssetDatabase, value); }
        }

#else
    public const bool kUseAssetDatabase = false;
#endif

        const string kiOS = "IOS";

        const string kAndroid = "Android";

        const string kStandaloneWindows = "StandaloneWindows";

        public const string kAssetBundle = "AssetBundle";

        public const string kBuildin = "buildin";

        public const string kManifest = "manifest.bin";

        public const string kSharedAssetBundle = "shared";

        public const string kBaseDownloadUrl = "http://192.168.0.109/Res/";

        public static string GetAssetBundlePath(string assetBundleName)
        {
            string path = Path.Combine(Application.persistentDataPath, kAssetBundle, assetBundleName);
            if (File.Exists(path))
                return path;
            path = Path.Combine(Application.streamingAssetsPath, kAssetBundle, assetBundleName);
            return path;
        }

        public static string GetPlatformName()
        {
#if UNITY_EDITOR
            return GetPlatformName(EditorUserBuildSettings.activeBuildTarget);
#else
        switch (Application.platform)
        {
            case RuntimePlatform.IPhonePlayer:
                return kiOS;
            case RuntimePlatform.Android:
                return kAndroid;
            case RuntimePlatform.WindowsPlayer:
            case RuntimePlatform.WindowsEditor:
                return kStandaloneWindows;
        }
        return null;
#endif
        }

#if UNITY_EDITOR
        static string GetPlatformName(BuildTarget buildTarget)
        {
            switch (buildTarget)
            {
                case BuildTarget.iOS:
                    return kiOS;
                case BuildTarget.Android:
                    return kAndroid;
                case BuildTarget.StandaloneWindows:
                case BuildTarget.StandaloneWindows64:
                    return kStandaloneWindows;
            }
            return null;
        }
#endif
    }
}